package com.tongzhou.util;

public class SessionUtil
{
	public static String createSessionId(String uid, String aid){
		String sid = uid + "_" + aid;
		return sid;
	}
	
	public static void setAttribute(String sid, String key, Object value)
	{
		// get memory session by sid then set attribute in the session
		MemSession session = MemSession.getSession(sid);
		session.setAttribute(key, value);
	}
	
	public static void setAttribute(String sid, String key, Object value,int expiryTime)
	{
		// get memory session by sid then set attribute in the session
		//MemSession session = MemSession.getSession(sid,expiryTime);
		//session.setAttribute(key, value,expiryTime);
		MemSession session = MemSession.getNoExpirySession( sid );
		session.setNoExpiryAttribute(key, value);
	}

	public static Object getAttribute(String sid, String key)
	{
		// get memory session by sid then set attribute in the session
		//getSession(sid,false) getAttribute
		MemSession session = MemSession.getSession(sid,false);
		return session.getAttribute(key);
	}

	public static void removeAttribute(String sid, String key)
	{
		// get memory session by sid then set attribute in the session
		MemSession session = MemSession.getSession(sid);
		session.removeAttribute(key);
	}

	public static void invalidate(String sid)
	{
		// get memory session by sid then set attribute in the session
		MemSession session = MemSession.getSession(sid);
		session.invalidate();
	}
	
	public static boolean sessionExists(String sid)
	{
		return MemSession.sessionExists(sid);
	}
	
	public static void updateExpiryDate(String sid){
		MemSession.updateExpiryDate(sid);
	}
	
	public static void main(String[] args)
	{
		System.out.println("ok");
	}
}
